<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>审批人审批申购单</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var purchaseId = new Ext.form.Hidden({
          name: 'id'
        });
        
        var orderNumber = new Ext.form.NumberField({
          fieldLabel: '申购序号',
          allowBlank: false,
          blankText: "申购单位不能为空",
          name: 'order_number',
          readOnly: true,
          anchor: '90%'
        });
        
        var purchaseUnit = new Ext.form.TextField({
          fieldLabel: '申购单位',
          allowBlank: false,
          blankText: "申购单位不能为空",
          name: 'purchase_unit',
          anchor: '90%',
          readOnly: true
        });
        
        //申购时间
        var actionDate = new Ext.form.DateField({
          fieldLabel: '申购时间',
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: true,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '90%'
        });


        var subDept = new Ext.form.TextField({
          fieldLabel: '实验室(科室)',
          name: 'sub_dept',
          readOnly: true,
          allowBlank: false,
          anchor: '90%'
        });

        var manager = new Ext.form.TextField({
          fieldLabel: '管理人',
          name: 'manager',
          anchor: '90%',
          readOnly: true,
          value:'<%=session[:applicant_name]%>'
        });

        var fundingSource = new Ext.form.TextField({
          fieldLabel: '经费来源',
          name: 'funding_source',
          allowBlank: false,
          readOnly: true,
          anchor: '90%'
        });

        var fundingAccount = new Ext.form.TextField({
          fieldLabel: '经费账号',
          name: 'funding_account',
          readOnly: true,
          anchor: '90%'
        });

        var fundingNature = new Ext.form.TextField({
          fieldLabel: '经费性质',
          name: 'funding_nature',
          readOnly: true,
          disabled: true,
          anchor: '90%'
        });

        var productName = new Ext.form.TextField({
          fieldLabel: '产品名称',
          name: 'product_name',
          allowBlank: false,
          readOnly: true,
          anchor: '90%'
        });

        var serviceLift = new Ext.form.NumberField({
          fieldLabel: '需用时间',
          name: 'service_lift',
          allowBlank: false,
          allowDecimals: false,
          allowNegative: false,
          readOnly: true,
          disabled: true,
          anchor: '90%'
        });


        var quantity = new Ext.form.NumberField({
          fieldLabel: '台件数',
          name: 'quantity',
          allowBlank: false,
          allowDecimals: false,
          allowNegative: false,
          readOnly: true,
          anchor: '90%'
        });

        var brand = new Ext.form.TextField({
          fieldLabel: '品牌',
          name: 'brand',
          readOnly: true,
          anchor: '90%'
        });

        var model = new Ext.form.TextField({
          fieldLabel: '型号',
          allowBlank: false,
          name: 'model',
          readOnly: true,
          anchor: '90%'
        });

        var specification = new Ext.form.TextField({
          fieldLabel: '型号规格',
          name: 'specification',
          readOnly: true,
          anchor: '95%'
        });

        var manufacturer = new Ext.form.TextField({
          fieldLabel: '生产单位',
          name: 'manufacturer',
          readOnly: true,
          anchor: '90%'
        });

        var estimatedPrice = new Ext.form.NumberField({
          fieldLabel: '预估单价',
          name: 'estimated_price',
          allowBlank: false,
          allowNegative: false,
          readOnly: true,
          anchor: '90%'
        });
        
        var estimatedAmount = new Ext.form.NumberField({
          fieldLabel: '预估总额',
          name: 'estimated_amount',
          readOnly: true,
          allowBlank: false,
          allowNegative: false,
          anchor: '90%'
        });
        
        var qualification = new Ext.form.TextArea({
          fieldLabel: '主要技术指标',
          name: 'qualification',
          height:60,
          readOnly: true,
          anchor: '97%'
        });

        var serviceRequest = new Ext.form.TextArea({
          fieldLabel: '服务要求',
          name: 'service_request',
          height:60,
          readOnly: true,
          anchor: '97%'
        });

        //供货时间
        var supplyDate = new Ext.form.DateField({
          fieldLabel: '供货时间',
          name: 'supply_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          readOnly: true,
          blankText: "申请日期必须选择",
          emptyText: '请选择日期...',
          anchor: '95%'
        });

        var supplyAddress = new Ext.form.TextField({
          fieldLabel: '供货地点',
          name: 'supply_address',
          readOnly: true,
          anchor: '96%'
        });
        
        var reason = new Ext.form.TextArea({
          fieldLabel: '申请理由及详细用途',
          allowBlank: false,
          name: 'reason',
          height:60,
          readOnly: true,
          anchor: '97%'
        });

        //竞标日期
        var beginDate = new Ext.form.DateField({
          fieldLabel: '竞标日期从',
          name: 'begin_date',
          id: 'begin_date',
          format: 'Y-m-d', //格式化日期
          width: '100',
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
          allowBlank: true,
          inputType: '2010-01-01',
          anchor: '90%',
          vtype: 'daterange',
          endDateField: 'end_date',
          allowBlank: false
        });
        var endDate = new Ext.form.DateField({
          fieldLabel: '到',
          name: 'end_date',
          id: 'end_date',
          format: 'Y-m-d', //格式化日期
          width: '100',
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
          allowBlank: false,
          inputType: '2010-01-01',
          anchor: '90%',
          vtype: 'daterange',
          startDateField: 'begin_date',
          allowBlank: false
        });
        

        var purchaseForm = new Ext.FormPanel({
          labelWidth: 75, // label settings here cascade unless overridden
          url:'/purchase/releasePurchase',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'order_number'
            }, {
              name: 'manager'
            }, {
              name: 'purchase_unit'
            }, {
              name: 'funding_source'
            }, {
              name: 'funding_account'
            }, {
              name: 'funding_nature'
            }, {
              name: 'action_date'
            }, {
              name: 'quantity'
            }, {
              name: 'brand'
            }, {
              name: 'supply_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'supply_address'
            }, {
              name: 'service_lift'
            }, {
              name: 'sub_dept'
            }, {
              name: 'product_name'
            }, {
              name: 'model'
            }, {
              name: 'specification'
            }, {
              name: 'manufacturer'
            }, {
              name: 'unit_price'
            }, {
              name: 'estimated_price'
            }, {
              name: 'estimated_amount'
            }, {
              name: 'qualification'
            }, {
              name: 'service_request'
            }, {
              name: 'reason'
            }]),
          frame:true,
          labelAlign: 'right',
          buttonAlign: 'center',
          //title: '添加申购单',
          bodyStyle:'padding:5px 5px 0',
          width: 760,
          //height:300,
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [purchaseUnit]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [subDept]
                }, {
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [manager]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [fundingSource]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [fundingAccount]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [fundingNature]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [serviceLift]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [productName]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [brand]
                },{
                  columnWidth: .5,
                  layout: 'form',
                  border: false,
                  items: [specification]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [manufacturer]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [quantity]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [estimatedPrice]
                },{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [estimatedAmount]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [qualification]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [reason]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .25,
                  layout: 'form',
                  border: false,
                  items: [supplyDate]
                },{
                  columnWidth: .75,
                  layout: 'form',
                  border: false,
                  items: [supplyAddress]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [serviceRequest]
                }]
            },{
              xtype: 'fieldset',
              defaults: {width: 750},
              title: '竞价信息',
              border: true,
              items: [{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: .25,
                      layout: 'form',
                      border: false,
                      items: [beginDate]
                    }, {
                      columnWidth: .25,
                      layout: 'form',
                      border: false,
                      items: [endDate]
                    }]
                }]
            },purchaseId],
          buttons: [{
              text: '发布',
              handler: function(){
                // check form value
                if (purchaseForm.form.isValid()) {
                  purchaseForm.form.submit({
                    method: 'GET',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        purchaseForReleaseWin.destroy();
                        purchaseDS.reload();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text: '取消',
              handler: function(){
                purchaseForReleaseWin.destroy();
              }
            }]
        });

        purchaseForm.form.load({
          url: '/purchase/edit?id=<%=params[:id]%>',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        
        purchaseForm.render('purchase_form');
      })
    </script>
  </head>
  <body>
    <div id="purchase_form"></div>
  </body>
</html>
